import { NMTopoBaseCommand } from '@app-cad/environments/nextmesh/types/command';

import { useState } from 'react';
import i18n from '@app-cad/common/utils/i18next';
import { CommandDialog } from '@amcax/base';
import { CommandLabeledItemWrapper } from '@app-cad/common/components/command-form/item-wrapper';
import { Select } from 'antd';
import {
  extraUiSchema,
  intersect,
  lineParam,
} from '../cmd-common/intersect-data';
import { MsComponent } from '../cmd-common/component';
export function Command({ onClose, title }) {
  const [mode, setMode] = useState<'line' | 'model'>('line');
  return (
    <CommandDialog
      title={title}
      onClose={onClose}
      placement='topLeft'>
      <CommandLabeledItemWrapper
        textClassName='text-reset'
        className='mt-5 px-5'
        label='类型'>
        <Select
          options={[
            { value: 'line', label: '选择目标边/直线/面' },
            { value: 'model', label: '选择目标体' },
          ]}
          value={mode}
          onChange={(val) => {
            if (val !== mode) {
              setMode(val);
            }
          }}
        />
      </CommandLabeledItemWrapper>
      {/* 线 */}
      {mode === 'line' && (
        <MsComponent
          onClose={onClose}
          formatParam={lineParam}
          formParams={{
            schemaParams: intersect.line,
            extraUiSchema: extraUiSchema.line,
          }}
        />
      )}
      {mode === 'model' && (
        <MsComponent
          onClose={onClose}
          formatParam={lineParam}
          formParams={{
            schemaParams: intersect.model,
            extraUiSchema: extraUiSchema.model,
          }}
        />
      )}
    </CommandDialog>
  );
}

export const cmdPointIntersect: NMTopoBaseCommand = {
  id: 'CmdPointIntersect',
  label: 'command.topo.point-intersect',
  icon: 'commands/curved/point-intersect',
  create: function (label: string, onClose: () => void) {
    return (
      <Command
        title={i18n.t(label)}
        onClose={onClose}
      />
    );
  },
};
